package multiThread;

/*
 * MultiThread: Train example
 * Without thread synchronization
 */

class Train5 implements Runnable {
	int avail = 1;

	public void run() {
		// try {Thread.sleep(1);} catch (InterruptedException e) {}
		Thread t = Thread.currentThread();
		String name = t.getName();
		if (avail == 1) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
			}
			System.out.println(name + " got the ticket.");
			avail--;
		} else {
			System.out.println(name + " didn't get the ticket.");
		}
	}
}

public class MyThread8 {
	public static void main(String args[]) {
		Train5 obj1 = new Train5();

		// Creation of thread.
		Thread t1 = new Thread(obj1);
		Thread t2 = new Thread(obj1);
		Thread t3 = new Thread(obj1);

		t1.setName("Raj");
		t2.setName("Geetha");
		t3.setName("Sita");

		// Thread is made runnable.
		t1.start();
		t2.start();
		t3.start();
	}
}